Bug 1969769 - Change uses of ast.Str with ast.Constant. r=firefox-build-system-review...
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 19 Aug 2025 05:09:09 +0000 (05:09 +0000)
committerMike Hommey <glandium@debian.org>
Wed, 19 Aug 2026 00:51:19 +0000 (09:51 +0900)
ast.Str was deprecated in python 3.12 and removed in 3.14. It inherited
from ast.Constant, `Str.s` was equivalent to `Constant.value`, so we can
use the latter on both old and newer python versions.

Differential Revision: https://phabricator.services.mozilla.com/D261512

Gbp-Pq: Topic fixes
Gbp-Pq: Name Bug-1969769-Change-uses-of-ast.Str-with-ast.Constant.patch

python/mozbuild/mozbuild/frontend/reader.py
python/mozbuild/mozbuild/vendor/rewrite_mozbuild.py

index 9f6292cb909def72470d6a85a59d5e99fe1a8a6b..89bf9995c1768292bd057ec74efcb98e733a191a 100644 (file)
@@ -470,7 +470,7 @@ class TemplateFunction:
             return c(
                 ast.Subscript(
                     value=c(ast.Name(id=self._global_name, ctx=ast.Load())),
-                    slice=c(ast.Index(value=c(ast.Str(s=node.id)))),
+                    slice=c(ast.Index(value=c(ast.Constant(value=node.id)))),
                     ctx=node.ctx,
                 )
             )
@@ -1039,8 +1039,8 @@ class BuildReader:
                 else:
                     # Others
                     assert isinstance(target.slice, ast.Index)
-                    assert isinstance(target.slice.value, ast.Str)
-                    key = target.slice.value.s
+                    assert isinstance(target.slice.value, ast.Constant)
+                    key = target.slice.value.value
             elif isinstance(target, ast.Attribute):
                 assert isinstance(target.attr, str)
                 key = target.attr
@@ -1051,11 +1051,11 @@ class BuildReader:
             value = node.value
             if isinstance(value, ast.List):
                 for v in value.elts:
-                    assert isinstance(v, ast.Str)
-                    yield v.s
+                    assert isinstance(v, ast.Constant)
+                    yield v.value
             else:
-                assert isinstance(value, ast.Str)
-                yield value.s
+                assert isinstance(value, ast.Constant)
+                yield value.value
 
         assignments = []
 
index cfcc0f18b9a9a9e7bdcc3cb13f67d89aa562f00b..de06b58819b6aa7f642b0afb9d940bef9741ecd2 100644 (file)
@@ -327,15 +327,13 @@ def assignment_node_to_source_filename_list(code, node):
     """
     if isinstance(node.value, ast.List) and "elts" in node.value._fields:
         for f in node.value.elts:
-            if not isinstance(f, ast.Constant) and not isinstance(f, ast.Str):
+            if not isinstance(f, ast.Constant):
                 log(
                     "Found non-constant source file name in list: ",
                     ast_get_source_segment(code, f),
                 )
                 return []
-        return [
-            f.value if isinstance(f, ast.Constant) else f.s for f in node.value.elts
-        ]
+        return [f.value for f in node.value.elts]
     elif isinstance(node.value, ast.ListComp):
         # SOURCES += [f for f in foo if blah]
         log("Could not find the files for " + ast_get_source_segment(code, node.value))